#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QSerialPort>
#include <QSettings>  //读写ini文件
#include <QMessageBox>
#include <QDateTime>
#include <QSplineSeries>
#include <QChartView>
#include <QDateTimeAxis>
#include <QValueAxis>
#include <QTimer>
#include <QDebug>
#include <QRandomGenerator>


#include "dialog.h"

QT_CHARTS_USE_NAMESPACE   //使用QChart必须要添加这句

QT_BEGIN_NAMESPACE
namespace Ui {
class MainWindow;
}
QT_END_NAMESPACE

#pragma pack(push,1)  // 字节对齐
typedef union BufDouble {
    struct {
        char tag;
        double n[12];
        quint16 crc16;
    };
    char b[1+sizeof(double) * 12+2];
} BUF_DOUBLE;
#pragma pack(pop)   // 字节对齐END

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();
    QSerialPort *serialPort;
    Dialog *d;

private slots:
    void readRequest();
    void on_pushButton_clicked();
    void on_pushButton_2_clicked();
    void changeComName(QString comname, int value);
    void addpiont();
    void setLedOff();
    void setLedOn();

private:
    Ui::MainWindow *ui;
    BUF_DOUBLE bufdouble;
    QLabel *ComStatic, *LedStatic, *ClockStatic;
    QSplineSeries *series1, *series2;
    QChart *chart;
    QDateTimeAxis *axisX;
    QValueAxis *axisY;
    QTimer *timer, *ledOff, *clocktime;         //计时器
    QFile *file;
    void logs(QByteArray buf);

    QDateTime momentInTime;
    int mm = 2;
    void setCom();
    void drawLine(int i1, int i2);
    quint16 CRC16(unsigned char *buf, int len);
};
#endif // MAINWINDOW_H
